<?php

class Users extends Model_Abstract
{
	protected $_table_name = table_users;
	
    protected $_users = array(
		'3', '4', '5', '6'
    );
	
	protected function _init()
	{
		parent::_init();
	}

    public function updateKarma( $user_id, $karma )
    {
		switch( $karma )
		{
			case 'review':
			case 'comment':
			$karma = 10;
			break;
			case 'vote':
			$karma = 2;
			break;
		}

		$sql = "UPDATE " . table_users . " SET user_karma=user_karma+". $karma ." WHERE user_id='$user_id';";
		$this->_db->get_results($sql);
    }
    
    public function getRandomUser( $_used_users )
    {
		$count = count( $this->_users );
		for( $i = 0; $i < $count; $i++ )
		{
			$index = rand(0, $count-1);
			if( !in_array( $this->_users[$index], $_used_users ) )
			{
			return $this->_users[$index];
			}
		}
		
		for( $i = 0; $i < $count; $i++ )
		{
			$index = rand(0, $count-1);
			if( !in_array( $this->_users[$index], $_used_users ) )
			{
			return $this->_users[$index];
			}
		}

		return false;
    }
    
}